/*************************************************
Author: byron
Date: 11/03/2012
Description:
Notes: 
*************************************************/

#ifndef __CSkillAffect_h__
#define __CSkillAffect_h__

#include "CTArray.h"
#include "commclass.h"
#include "CSkillEffect.h"

class CSkillAffect
{
public:
    enum SKILL_TARGET_TYPE_TAG
    {
        SKILL_TARGET_NONE               = 0,    
        SKILL_TARGET_NEAREST            = 1,        //离自己最近的一个
        SKILL_TARGET_NEAR_WHOLE         = 2,        //全场最近的一个
        SKILL_TARGET_NEAR_FRONT         = 3,        //前场最近的一个
        SKILL_TARGET_NEAR_BACK          = 4,        //后场最近的一个
        SKILL_TARGET_NEAR_SWORD         = 5,        //全场最近的一个魔剑士
        SKILL_TARGET_NEAR_BOW           = 6,        //全场最近的一个魔猎手
        SKILL_TARGET_NEAR_MAGE          = 7,        //全场最近的一个魔法师
        SKILL_TARGET_NEAR_AWL           = 8,        //全场最近的一个魔斗士
        
        SKILL_TARGET_ALL_ROLE           = 9,        //全场所有
        SKILL_TARGET_ALL_FRONT          = 10,       //前场所有
        SKILL_TARGET_ALL_BACK           = 11,       //后场所有

        SKILL_TARGET_FAR_WHOLE          = 20,       //全场最后的一个
        SKILL_TARGET_ALL_RANDOM         = 21,       //全场随机的一个
        SKILL_TARGET_HP_LOWEST          = 22,       //生命上限最低的一个
        SKILL_TARGET_HP_HIGHEST         = 23,       //生命上限最高的一个

        SKILL_TARGET_PLAYER             = 24,       //全场主角
        SKILL_TARGET_PARTNER            = 25,       //全场伙伴

        //以下只适用于status
        SKILL_TARGET_ONESELF            = 12,       //角色自己
        SKILL_TARGET_ALL_TEAMMATE       = 13,       //所有队友
        SKILL_TARGET_ALL_ENEMY          = 14,       //所有敌人
        SKILL_TARGET_ENEMY_I_ATK        = 15,       //当前攻击敌人
        SKILL_TARGET_ENEMY_SKILL        = 16,       //技能所指敌人
        SKILL_TARGET_ENEMY_TO_ME        = 17,       //攻击我的敌人
        SKILL_TARGET_ENEMY_KILL_ME      = 18,       //杀死我的敌人
        SKILL_TARGET_TEAMMATE_AFF       = 19,       //对我使用技能的队友
    };

    enum SKILL_TARGET_STRU       
    {
        SKILL_TARGET_STRU_MAIN              = 1,        //主目标(至多选出一个非自身的目标)
        SKILL_TARGET_STRU_ONESELF_INVO      = 2,        //波及施法者自己
        SKILL_TARGET_STRU_DISTAN_INVO       = 3,        //波及一段距离上目标
        SKILL_TARGET_STRU_CENTRE_INVO       = 4,        //波及中心范围内目标
        SKILL_TARGET_STRU_GROUP             = 5,        //群体目标
        SKILL_TARGET_STRU_BACK_INVO         = 6,        //波及身后距离上目标
        SKILL_TARGET_STRU_MAIN_INVO         = 7,        //波及主目标
    };

    CSkillAffect()
    {
        //如果ID为非正数 则这个技能功能无效
        Clear();
    }

    void Clear()
    {
        _bIsValid = false;
        _bIsToEnemy = false;
        _bIsPhy = false;
        _ucTargetType = 0;
        _ucTargetStru = 0;
        _uiID = 0;
        _iMaxAtkDistance = 0;
        _iRecommendDistance = 0;
        _iEffectRange = 0;
        _iSkillAtkValue = 0;

        _astSkillEff.Clear();
    }

    virtual ~CSkillAffect(){}

    bool IsTargetStruMain() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_MAIN;
    }
    bool IsTargetStruOneselfInvo() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_ONESELF_INVO;
    }
    bool IsTargetStruDistanInvo() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_DISTAN_INVO;
    }
    bool IsTargetStruCentreInvo() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_CENTRE_INVO;
    }
    bool IsTargetStruMainInvo() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_MAIN_INVO;
    }
    bool IsTargetStruGroup() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_GROUP;
    }
    bool IsTargetStruBackInvo() const
    {
        return _ucTargetStru == SKILL_TARGET_STRU_BACK_INVO;
    }

    bool IsValidID() const {return (_uiID > 0);}

    bool IsValid() const {return _bIsValid;}
    bool IsToEnemy() const {return _bIsToEnemy;}
    bool IsPhy() const {return _bIsPhy;}
    unsigned char GetTargetType() const { return _ucTargetType;};
    unsigned char GetTargetStru() const {return _ucTargetStru;}
    unsigned int GetID() const {return _uiID;}
    int GetMaxAtkDistance() const { return _iMaxAtkDistance;}
    int GetRecommendDistance() const { return _iRecommendDistance;}
    int GetEffectRange() const {return _iEffectRange;}
    int GetAtkValue() const { return _iSkillAtkValue;}

    int GetSkillEffectSize() const {return _astSkillEff.Size();}

    unsigned int GetSkillEffectID(int iIndex) const
    {
        return _astSkillEff[iIndex].GetID();
    }

    CSkillEffect& GetSkillEffect(int iIndex)
    {
        if (iIndex < 0 || iIndex >= _astSkillEff.Size())
        {
            CT_ERROR(("skill effect size(%d) but index(%d)",
                       _astSkillEff.Size(),iIndex));
             return _astSkillEff[0];
        }

        return _astSkillEff[iIndex];
    }

    void SetValid(bool bIsValid){_bIsValid = bIsValid;}
    void SetToEnemy(bool bIsToEnemy){_bIsToEnemy = bIsToEnemy;}
    void SetPhy(bool bIsPhy){_bIsPhy = bIsPhy;}
    void SetTargetType(unsigned char ucTargetType)
    {
        _ucTargetType = ucTargetType;
    }
    void SetTargetStru(unsigned char ucTargetStru)
    {
        _ucTargetStru = ucTargetStru;
    }
    void SetID(unsigned int uiID){_uiID = uiID;}
    void SetMaxAtkDistance(int iMaxAtkDistance)
    {
        _iMaxAtkDistance = iMaxAtkDistance;
    }
    void SetRecommendDistance(int iRecommendDistance)
    {
        _iRecommendDistance = iRecommendDistance;
    }
    void SetEffectRange(int iEffectRange){_iEffectRange = iEffectRange;}
    void SetAtkValue(int iSkillAtkValue){_iSkillAtkValue = iSkillAtkValue;}
    void AddSkillEffect(CSkillEffect& stSkillEffect)
    {
        _astSkillEff.AddOneItem(stSkillEffect);
    }

    int GetSwimEffect(bool& bHasSwimEffect, CSkillEffect& stSwimEffect);
    int GetHitBackEffect(bool& bHasHitBackEffect,
            CSkillEffect& stHitBackEffect);
    int GetPullEffect(bool& bHasPullEffect, CSkillEffect& stPullEffect);

    void DumpSkillAffectInfo();

private:
    bool _bIsValid;                 //该对象是否生效
    bool _bIsToEnemy;               //是否是对敌人
    bool _bIsPhy;                   //是否物理攻击
    unsigned char _ucTargetType;    //选择目标的方式
    unsigned char _ucTargetStru;    //目标结构
    unsigned int _uiID;             //资源ID
    int _iMaxAtkDistance;           //最大攻击距离
    int _iRecommendDistance;        //推荐攻击距离
    int _iEffectRange;              //有效波及距离
    int _iSkillAtkValue;            //技能系数
        
    CTLib::CTArray<CSkillEffect, MAX_EFFECT_PER_SKILL> _astSkillEff;
};

#endif // __CSkillAffect_h__

